/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
class Solution {
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if(n < 3) {
            return n;
        }
        int slow = 2;
        int fast = 2;
        while (fast < n) {
            if(nums[slow - 2] != nums[fast]) {
                nums[slow ++] = nums[fast];
            }
            fast ++;
        }
        return slow;
    }
}
public class Main {
    public static void main(String[] args) {
        int[] nums = {1,1,1,2,2,2,3,3,3,3};
        Solution solution = new Solution();
        int n = solution.removeDuplicates(nums);
        System.out.println(n);
        for (int i = 0; i < n; i++) {
            System.out.print(nums[i] + " ");
        }

    }
}